<?php

namespace app\system\model;

use think\Model;

class SysRoleModel extends Model{
    protected $table = "sys_role";
    protected $pk = "rold_id";

    protected $field = [
        "role_id",          //主键  
        "r_name",           //角色名称
        "auth"              //权限
    ];

    public function getRoleListWithPaginate($pageSize)
    {
        $roleList = $this->order(["role_id" => "desc"])->paginate($pageSize);
        return $roleList;
    }

    public function addRoleData($data){
        $result = $this->allowField(true)->save($data);
        return $result;
    }

    public function updRoleData($data,$role_id){
        $result = $this->allowField(true)->force(true)->save($data,["role_id"=>$role_id]);
        return $result;
    }

    public function getRoleById($role_id){
        $role = $this->where(["role_id"=>$role_id])->find();
        return $role;
    }

    public function delRoleById($role_id){
        $result = $this->where(["role_id"=>$role_id])->delete();
        return $result;
    }
}